/**
 * Copyright (c) qc&Bull Co.,LTD.
 * All right reserved.
 */

package cn.zxd.lis.vschema;

import cn.zxd.lis.schema.LDMaxNoSchema;
import cn.zxd.util.*;

/**
 * <p>ClassName: LDMaxNoSet </p>
 * <p>Description: LDMaxNoSchemaSet类文件 </p>
 * <p>Company: qc&Bull Co.,LTD </p>
 * @Database: IIEP_Data_Model
 * @author：anonymous
 * @CreateDate：2015-11-22
 */
public class LDMaxNoSet extends SchemaSet
{
    // @Method
    public boolean add(LDMaxNoSchema cSchema)
    {
        return super.add(cSchema);
    }

    public boolean add(LDMaxNoSet cSet)
    {
        return super.add(cSet);
    }

    public boolean remove(LDMaxNoSchema cSchema)
    {
        return super.remove(cSchema);
    }

    public LDMaxNoSchema get(int index)
    {
        LDMaxNoSchema tSchema = (LDMaxNoSchema)super.getObj(index);
        return tSchema;
    }

    public boolean set(int index, LDMaxNoSchema cSchema)
    {
        return super.set(index, cSchema);
    }

    public boolean set(LDMaxNoSet cSet)
    {
        return super.set(cSet);
    }

    /**
     * 数据打包，按 XML 格式打包，顺序参见<A href ={@docRoot}/dataStructure/tb.html#PrpLDMaxNo描述/A>表字段
     * @return: String 返回打包后字符串
     */
    public String encode()
    {
        StringBuffer strReturn = new StringBuffer("");
        int n = this.size();
        for (int i = 1; i <= n; i++)
        {
            LDMaxNoSchema aSchema = this.get(i);
            strReturn.append(aSchema.encode());
            if (i != n)
                strReturn.append(SysConst.RECORDSPLITER);
        }
        return strReturn.toString();
    }

    /**
     * 数据解包
     * @param: str String 打包后字符串
     * @return: boolean
     */
    public boolean decode(String str)
    {
        int nBeginPos = 0;
        int nEndPos = str.indexOf('^');
        this.clear();
        while (nEndPos != -1)
        {
            LDMaxNoSchema aSchema = new LDMaxNoSchema();
            if (aSchema.decode(str.substring(nBeginPos, nEndPos)))
            {
                this.add(aSchema);
                nBeginPos = nEndPos + 1;
                nEndPos = str.indexOf('^', nEndPos + 1);
            }
            else
            {
                // @@错误处理
                this.mErrors.copyAllErrors(aSchema.mErrors);
                return false;
            }
        }
        LDMaxNoSchema tSchema = new LDMaxNoSchema();
        if (tSchema.decode(str.substring(nBeginPos)))
        {
            this.add(tSchema);
            return true;
        }
        else
        {
            // @@错误处理
            this.mErrors.copyAllErrors(tSchema.mErrors);
            return false;
        }
    }
}
